package com.ruoyi.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @fileName: CollectionUtils
 * @description: TODO
 * @author: Li Wenbo
 * @date: 2020-3-10 11:08
 * @version: V1.0
 */
public class CollectionUtils {
    /**
     * list对象中的模糊查询
     * @param name
     * @param list
     * @return
     */
    public static List search(String name, List list){
        List results = new ArrayList();
        Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE); //不区分大小写
        for(int i=0; i < list.size(); i++){
            Matcher matcher = pattern.matcher((String)list.get(i));
            if(matcher.find()){
                results.add(list.get(i));
            }
        }
        return results;
    }
}
